﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Bon.It.Server
{
    using System.Data.Linq;

    using Bon_It.Model;

    public partial class ContractManager
    {
        #region Implementation of IBelege

        /// <summary>
        /// Gets the <see cref="Belege"/> by id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public Belege GetBelegById(long id)
        {
            // load the other data too.
            DataLoadOptions dlo = new DataLoadOptions();
            dlo.LoadWith<Belege>(b=>b.Rechnung);
            dlo.LoadWith<Rechnung>(r=>r.Artikel);
            dlo.LoadWith<Artikel>(a=>a.Taxes);
            dlo.LoadWith<Artikel>(a=>a.Gebinde);

            using (var context = this.GetDataContext(dlo))
            {
                return context.Belege.FirstOrDefault(b => b.Id == id);
            }
        }

        #endregion
    }
}
